package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.commons.ResponseResult;
import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/5/8
 * @description
 */
@RestController
@RequestMapping("city")
public class CityController {

    @Resource
    private CityService cityService;

    // 城市列表
    @GetMapping
    public ResponseResult  cityList(){
        List<City> list = cityService.list();
        return  ResponseResult.success().data(list);
    }

    // 根据id获取城市信息
    @GetMapping("{id}")
    public City  getOneCity(@PathVariable("id") Integer id){
        City city = cityService.getById(id);
        return city;
    }

    @PostMapping
    public ResponseResult  addCity(@RequestBody City city){

        cityService.save(city);
        return  ResponseResult.success().data(city);
    }


}
